/**
 * 项目名称:
 *
 * @Author: 夏国倩
 * @Date: 2023/10/10 11:30
 * @Copyright
 */
package IO2;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

//对第一个程序进行改造，循环方式
/*
该程序的缺点：一次读取一个字节byte，这样内存和硬盘之间的交互太频繁，基本上时间、资源都耗费在了交互连接上
 */
public class FileInputStreamTest2 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("E:\\code\\TestDemo\\src\\demo\\IO2\\temp");
           /* while (true) {
                int readDate = fis.read();
                if (readDate == -1) {
                    break;
                }
                System.out.println(readDate);
            }*/
            //改造while循环
            int readData=0;
            while ((readData=fis.read())!=-1){
                System.out.println(readData);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (fis !=null){
                try{
                    fis.close();
                }catch (IOException e){
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
